package com.weakteam.androidclient.data.domain;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Nail
 */
public class Menu {

    private Integer id;
    private String name;
    private String description;
    private String ico;
    private String image;
    private String properties;

    private List<Goods> goods;

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getIco() {
        return ico;
    }

    public String getImage() {
        return image;
    }

    public String getProperties() {
        return properties;
    }

    public List<Goods> getGoods() {
        return goods;
    }

    public Menu(JSONObject jMenu) {
        Object obj = null;

        obj = jMenu.get("id");
        if (obj != null) {
            this.id = ((Long)obj).intValue();
        }

        obj = jMenu.get("name");
        if (obj != null) {
            this.name = (String)obj;
        }

        obj = jMenu.get("description");
        if (obj != null) {
            this.description = (String)obj;
        }

        obj = jMenu.get("ico");
        if (obj != null) {
            this.ico = (String)obj;
        }

        obj = jMenu.get("image");
        if (obj != null) {
            this.image = (String)obj;
        }

        obj = jMenu.get("properties");
        if (obj != null) {
            this.properties = (String)obj;
        }

        obj = jMenu.get("properties");
        if (obj != null) {
            this.properties = (String)obj;
        }

        JSONArray jArray = (JSONArray)jMenu.get("goods");
        int n = jArray.size();
        this.goods = new ArrayList<Goods>(n);
        for(int i = 0; i < n; i++) {
            JSONObject jGoods = (JSONObject)jArray.get(i);
            this.goods.add(new Goods(jGoods));
        }
    }

}
